#==============================================================================
#  _   _                         ____                _             
# | | | | ___  _ __ ___   ___   / ___|___  _ __ ___ (_)_ __   __ _ 
# | |_| |/ _ \| '_ ` _ \ / _ \ | |   / _ \| '_ ` _ \| | '_ \ / _` |
# |  _  | (_) | | | | | |  __/ | |__| (_) | | | | | | | | | | (_| |
# |_| |_|\___/|_| |_| |_|\___|  \____\___/|_| |_| |_|_|_| |_|\__, |
#                                                            |___/ 
#------------------------------------------------------------------------------
# Project:	Home Coming / 2D platform
# Author:	zx.longgi
# Time:		08/06-2010 
# Usage:	A minimum functioning engine runner.  
# Description:	Small and compact engine runner
# ClassName:	run_engine_test
#==============================================================================
import sys
import os
import os.path
sys.path.insert(0,'..')
import PythonOgreConfig
import time
import ogre.renderer.OGRE as ogre 

from zfile_concrete import zfile_concrete

class run_engine_test(ogre.Root):
	"""A minimum functioning engine runner"""	
	def __init__(self, plugins_path='../plugins.cfg', \
	resource_path='../resources.cfg'):
		"""simple init"""
		ogre.Root.__init__(self, plugins_path)
		self.plugins_path = plugins_path
		self.resource_path = resource_path
		self.sm = None
		self.s_root = None
		self.rgm = ogre.ResourceGroupManager.getSingleton()
		
		self._choose_render_engine()
		self.initialise(False)
		self.initialisePlugins()
		
		self.sm = self.createSceneManager("TerrainSceneManager" ) \
			#ogre.ST_GENERIC)
		self.window = self.createRenderWindow("Woot", 800, 600, False)
		
		self.sm.setAmbientLight(ogre.ColourValue(1, 1, 1))
		self.camera = self.sm.createCamera("camera")
		self.camera.setPosition(0, 100, 500)
		self.camera.lookAt(ogre.Vector3(0, 0, 0))
		self.camera.setNearClipDistance(15)
		self.viewport = self.window.addViewport(self.camera)
		self.viewport.setBackgroundColour(ogre.ColourValue(0, 0, 0))
		
		self.rgm.initialiseAllResourceGroups()
		
		
	def _choose_render_engine(self):
		rend_list = self.getAvailableRenderers()
		for ren in rend_list:
		    print ren.getName()
		    cap = ren.getCapabilities()
		    if cap:
			print "MaxPointSize:", cap.getMaxPointSize()
			print "Stencil stuff:", cap.getStencilBufferBitDepth()
			opts = ren.getConfigOptions()
			print "Opts:", opts
			print "Opts keys:",opts.keys()
			for i in opts:
			    print "Key:",i.key
			    print i.value.currentValue
			    print i.value.name
			    print i.value.immutable
			    for v in i.value.possibleValues:
				print "Posible Value", v
			    
			print dir(opts)
			print "Opts", opts['Video Mode']
			print"Viewo Mode:",  \
				ren.getConfigOptions()['Video Mode']
		self.setRenderSystem(rend_list[-1])

def main():
	root = run_engine_test(plugins_path='../plugins.cfg.nt')
	weu = ogre.WindowEventUtilities()
	while not root.window.isClosed():
		weu.messagePump()
		if root.window.isActive():
			# all eyes are on us, render away
			root.renderOneFrame()
			time.sleep(.0001)
		else:
			# we got minimized or de-focused, so slow it down and stop
			# rendering until we get focus back
			time.sleep(1)
	root.shutdown()
	sys.exit(0)

if __name__ == "__main__":
	#main()
	cncstr = os.path.join(os.getcwd(), "test.concrete")
	zf = zfile_concrete(cncstr)
	print cncstr
	#zf.open_and_prepare_concrete_file(cncstr)
	#print lines
	